package org.example;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
 * 测试时间范围计算
 */
public class TestTimeRange {
    public static void main(String[] args) {
        System.out.println("=== 测试时间范围计算 ===");
        
        // 从2023年7月开始生成数据，到2025年8月结束
        LocalDate startDate = LocalDate.of(2023, 7, 1);
        LocalDate endDate = LocalDate.of(2025, 8, 31);
        
        System.out.println("开始日期: " + startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        System.out.println("结束日期: " + endDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        
        // 计算总月数
        long totalMonths = ChronoUnit.MONTHS.between(startDate, endDate);
        System.out.println("总月数: " + totalMonths);
        
        // 模拟每月订单数量计算
        int totalOrders = 1000000; // 100万订单
        System.out.println("\n每月订单数量预测:");
        
        LocalDate monthDate = startDate;
        int monthCount = 0;
        while (monthDate.isBefore(endDate)) {
            long monthsFromStart = ChronoUnit.MONTHS.between(startDate, monthDate);
            
            // 递增趋势：每月增长3%
            double growthRate = 1.03;
            double monthlyRatio = Math.pow(growthRate, monthsFromStart);
            
            // 基础每月订单数
            int baseMonthlyOrders = totalOrders / 26;
            
            // 确保每月至少有100个订单
            int monthlyOrders = (int) (baseMonthlyOrders * monthlyRatio);
            monthlyOrders = Math.max(monthlyOrders, 100);
            
            System.out.printf("%s: %d个订单 (增长率: %.2f)%n", 
                monthDate.format(DateTimeFormatter.ofPattern("yyyy-MM")), 
                monthlyOrders, 
                monthlyRatio);
            
            monthDate = monthDate.plusMonths(1);
            monthCount++;
            
            // 只显示前12个月和后12个月
            if (monthCount > 12 && monthCount < totalMonths - 12) {
                if (monthCount == 13) {
                    System.out.println("... (中间月份省略) ...");
                }
                continue;
            }
        }
        
        System.out.println("\n=== 测试完成 ===");
    }
}
